#include "node_rbf.h"

#include "ann_math.h"

namespace ann
{

const double node_rbf::tick(const double* pInVec, const UINT pInCnt)
{
    assert( pInCnt == m_inCnt );

    this->SaveInVec(pInVec);

    m_dis = ann::math::EulerDis(pInVec, pInVec+m_inCnt, m_ctVec);

    m_data = m_exFunc(m_dis, m_sigma);

    return m_data;
}

const UINT node_rbf::UpdateW(const double pYita, const double pWeight)
{
    double  dSigma = pYita * pWeight * m_data * m_dis*m_dis / (m_sigma*m_sigma*m_sigma);
    double* dCt = new double[m_inCnt];
    std::fill_n(dCt, m_inCnt, 0.0);

    for( UINT i = 0; i < m_inCnt; ++i )
    {
        dCt[i] = pYita * pWeight * m_data * (m_inVec[i]-m_ctVec[i]) / (m_sigma*m_sigma);
        m_ctVec[i] += dCt[i];
    }

    m_sigma += dSigma;

    return eann_Normal;
}

}
